@ Echo off

SetLocal EnableExtensions EnableDelayedExpansion
Set VbsFname=%~dpn0.vbs
Echo 0=%~f0
Echo VbsFname=%VbsFname%

:: Demo for Eric, Lou & Bruce for DTCC
::    RA settings to test this script
::       Shell Plugin
::          Step = Run a Shell Script
::             Directory offset = {whatever you're using}
::             xargs = {nothing}
::             Shell Script = {paste this file}
::             Interpreter = {nothing}
::             Daemon = not selected
::             Output File = not specified

:: This is the BATCH portion that takes the VBS portion and saves it to a
::    VBS file then runs CScript on it.

::    Author:     paul_m_thompson@yahoo.com
::    File:       C:\Users\Public\Documents\Virtual Machines\VmWareShare\Source\awk\DTCC\DTCC_POC.bat
::    Script:     DTCC_POC.bat
::    Revision:   $$
::    Id:         $$


If Exist "%VbsFname%" Del /F "%VbsFname%"
:: Copy everything after line 15 to file with same name as this file but .VBS
:: The "skip" param should be the line number of the "Last Line of BATCH portion" below.
For /F "skip=43 delims=~ tokens=1*" %%I In (%0) Do echo %%I>>"%VbsFname%"
:: Run created file with CScript
c:\Windows\System32\cscript.exe "%VbsFname%"

Exit /B
:: ****************************************************************************
:: ****************************************************************************
:: !! ALERT!!  Every blank line in the VBScript portion must have a comment
::     char as first char, otherwise the BATCH portion outputs those lines
::     as "ECHO is off."
:: ****************************************************************************
REM :: Last Line of BATCH portion
REM ' First Line of VBScript portion
Option Explicit
'
' ****************************************************************************
'
Dim g_Wsh , i , arg , wshNet , wshEnv
Set g_Wsh = CreateObject("WScript.Shell")
Set wshNet = WScript.CreateObject("WScript.Network")
Set wshEnv = g_Wsh.Environment("SYSTEM")
'
'
' ****************************************************************************
' Try to iterate some VBScript system properties
'
' VBScript executable diagnostic info
'
LogThis vbCrLf & "WScript properties:"
LogThis  "   BuildVersion=" & WScript.BuildVersion & vbCrLf & _
         "   Version=" & WScript.Version & vbCrLf & _
         "   Name=" & WScript.Name & vbCrLf & _
         "   Path=" & WScript.Path & vbCrLf & _
         "   FullName=" & WScript.FullName & vbCrLf & _
         "   Interactive=" & WScript.Interactive & vbCrLf & _
         "   ScriptName=" & WScript.ScriptName & vbCrLf & _
         "   ScriptFullName=" & WScript.ScriptFullName & vbCrLf
'
LogThis vbCrLf & "WshShell properties:"
LogThis  "   CurrentDirectory=" & g_Wsh.CurrentDirectory & vbCrLf & _
         "   Environment:"
For Each arg in wshEnv
   LogThis  "      " & arg & "=" & wshEnv(arg)
Next
'
'
'
' ****************************************************************************
' ****************************************** see if RA passed us the arguments
'
' WScript.Arguments and WScript.Arguments.UnNamed are numerically indexed Collections that
'     must be iterated using index from 0 to Arguments.Length-1
' WScript.Arguments.Named is a key:value Collection specified on command line like this "/key:value".
'     This Collection may be iterated using a For Each
'
'  Command                                                                 Return value
'  line arg          WScript.Arguments.Named.Item()            .Exists()   TypeName & length
'  ---------------   ---------------------------------------   ----------  -------------------
'  /fred1            WScript.Arguments.Named.Item("fred1")     True        Empty
'  /fred2:           WScript.Arguments.Named.Item("fred2")     True        String  length=0
'  /fred3:x          WScript.Arguments.Named.Item("fred3")     True        String  length=1
'  "/fred4: "        WScript.Arguments.Named.Item("fred4")     True        String  length=1
'  /fred5:" "        WScript.Arguments.Named.Item("fred5")     True        String  length=1
'                    WScript.Arguments.Named.Item("fred6")     False       Empty
'
'
'	key portion of /key:value     value portion of /key:value   Object type returned by obj_Named_Args.Item("key")
'	---------------------------	---------------------------   --------------------------------------------------
' 	No				                  n/a				               Empty
'	Yes				               nothing			               String, Len=0
'	Yes				               something		               String, Len>0
'
LogThis vbCrLf & "Iterate WScript.Arguments:"
For i=0 to WScript.Arguments.Length-1
   LogThis "   Arguments(" & CStr(i) & ") == '" & WScript.Arguments(i) & "'"
Next
'
LogThis vbCrLf & "Iterate WScript.Arguments.UnNamed:"
For i=0 to WScript.Arguments.UnNamed.Length-1
   LogThis "   UnNamed(" & CStr(i) & ") == '" & WScript.Arguments.UnNamed(i) & "'"
Next
'
LogThis vbCrLf & "Iterate WScript.Arguments.Named:"
For Each arg in WScript.Arguments.Named
   LogThis "   Named(" & arg & ") == '" & WScript.Arguments.Named(arg) & "'"
Next
'
' ****************************************************************************
'
LogThis vbCrLf & "WshNetwork properties:"
LogThis  "   ComputerName=" & wshNet.ComputerName & vbCrLf & _
         "   UserDomain=" & wshNet.UserDomain & vbCrLf & _
         "   UserName=" & wshNet.UserName & vbCrLf
'
'
' ****************************************************************************
' Cleanup
'
Set wshEnv = Nothing
Set wshNet = Nothing
Set g_Wsh = Nothing
'
' ****************************************************************************
' ****************************************************************************
'
Sub LogThis(str)
   WScript.Echo str
   ' g_Wsh.LogEvent 4,str
End Sub
'
' ****************************************************************************
